package net.lab1024.sa.user.module.business.course.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.lab1024.sa.common.common.domain.PageResult;
import net.lab1024.sa.common.common.domain.ResponseDTO;
import net.lab1024.sa.user.constant.UserSwaggerTagConst;
import net.lab1024.sa.user.module.business.course.domain.form.CourseOrderAddForm;
import net.lab1024.sa.user.module.business.course.domain.form.CourseOrderQueryForm;
import net.lab1024.sa.user.module.business.course.domain.form.CourseQueryForm;
import net.lab1024.sa.user.module.business.course.domain.vo.CourseOrderVO;
import net.lab1024.sa.user.module.business.course.domain.vo.CourseVO;
import net.lab1024.sa.user.module.business.course.service.CourseOrderService;
import net.lab1024.sa.user.module.business.course.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 课程表 Controller
 *
 * @Author jabari
 * @Date 2023-08-05 16:37:20
 * @Copyright 51dev.cn
 */

@RestController
@Api(tags = UserSwaggerTagConst.Business.COURSE)
public class CourseController {

    @Autowired
    private CourseService courseService;


    @Autowired
    private CourseOrderService courseOrderService;

    @ApiOperation("分页查询课程 @author jabari")
    @PostMapping("/course/queryPage")
    public ResponseDTO<PageResult<CourseVO>> queryPage(@RequestBody @Valid CourseQueryForm queryForm) {
        return ResponseDTO.ok(courseService.queryPage(queryForm));
    }

    @ApiOperation("课程报名 @author jabari")
    @PostMapping("/course/createOrder")
    public ResponseDTO<String> createOrder(@RequestBody @Valid CourseOrderAddForm courseOrderAddForm){
        return courseOrderService.add(courseOrderAddForm);
    }

    @ApiOperation("分页查询课程订单 @author jabari")
    @PostMapping("/course/queryOrderPage")
    public ResponseDTO<PageResult<CourseOrderVO>> queryOrderPage(@RequestBody @Valid CourseOrderQueryForm queryForm) {
        return ResponseDTO.ok(courseOrderService.queryPage(queryForm));
    }


}
